#  Copyright (C) 2018 Yunify, Inc.
# 
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this work except in compliance with the License.
#  You may obtain a copy of the License in the LICENSE file, or at:
# 
#  http://www.apache.org/licenses/LICENSE-2.0
# 
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

kind: Service
apiVersion: v1
metadata:
  name: csi-neonsan-controller
  namespace: kube-system
  labels:
    app: "csi-neonsan"
    role: "controller"
    csi: "v0.3.0"
    owner: "yunify"
spec:
  selector:
    app: "csi-neonsan"
    role: "controller"
    csi: "v0.3.0"
    owner: "yunify"
  ports:
    - name: dummy
      port: 12345

---
kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: csi-neonsan-controller
  namespace: kube-system
  labels:
    app: "csi-neonsan"
    role: "controller"
    csi: "v0.3.0"
    owner: "yunify"
spec:
  serviceName: "csi-neonsan-controller"
  replicas: 1
  selector:
    matchLabels:
      app: "csi-neonsan"
      role: "controller"
      csi: "v0.3.0"
      owner: "yunify"
  template:
    metadata:
      labels:
        app: "csi-neonsan"
        role: "controller"
        csi: "v0.3.0"
        owner: "yunify"
    spec:
      serviceAccount: csi-neonsan-controller
      imagePullSecrets:
      - name: csi-neonsan
      containers:
      - name: csi-provisioner
        image: {{ neonsan_csi_provisioner_repo }}:{{ neonsan_csi_provisioner_tag }}
        args:
        - "--provisioner=csi-neonsan"
        - "--csi-address=$(ADDRESS)"
        - "--v=5"
        env:
        - name: ADDRESS
          value: /csi/csi.sock
        imagePullPolicy: "IfNotPresent"
        volumeMounts:
        - name: socket-dir
          mountPath: /csi
      - name: csi-attacher
        image: {{ neonsan_csi_attacher_repo }}:{{ neonsan_csi_attacher_tag }}
        args:
        - "--csi-address=$(ADDRESS)"
        - "--v=5"
        env:
        - name: ADDRESS
          value: /csi/csi.sock
        imagePullPolicy: "IfNotPresent"
        volumeMounts:
        - name: socket-dir
          mountPath: /csi
      - name: csi-snapshotter
        image: {{ neonsan_csi_snapshotter_repo }}:{{ neonsan_csi_snapshotter_tag }}
        args:
        - "--csi-address=$(ADDRESS)"
        - "--connection-timeout=15s"
        env:
        - name: ADDRESS
          value: /var/lib/csi/sockets/pluginproxy/csi.sock
        imagePullPolicy: "IfNotPresent"
        volumeMounts:
        - name: socket-dir
          mountPath: /var/lib/csi/sockets/pluginproxy
      - name: csi-neonsan
        image: {{ csi_neonsan_repo }}:{{ csi_neonsan_tag }}
        args :
        - "--nodeid=$(NODE_ID)"
        - "--endpoint=$(CSI_ENDPOINT)"
        - "--drivername=csi-neonsan"
        - "--config=/etc/neonsan/qbd.conf"
        - "--pools=kube"
        - "--protocol={{ neonsan_csi_protocol }}"
        - "--v=5"
        env:
        - name: NODE_ID
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: CSI_ENDPOINT
          value: unix:///csi/csi.sock
        imagePullPolicy: "IfNotPresent"
        volumeMounts:
        - name: socket-dir
          mountPath: /csi
        - name: server-config
          mountPath: /etc/neonsan
        - name: neonsan-cmd
          mountPath: /usr/bin
        - name: lib
          mountPath: /lib
        - name: usrlib
          mountPath: /usr/lib
      volumes:
      - name: socket-dir
        emptyDir: {}
      - name: server-config
        configMap:
          name: csi-neonsan
      - name: neonsan-cmd
        hostPath:
          path: /usr/bin
          type: DirectoryOrCreate
      - name: lib
        hostPath:
          path: /lib
      - name: usrlib
        hostPath:
          path: /usr/lib
